#ifndef CHAT_SERVICE_RPC_CLIENT_H
#define CHAT_SERVICE_RPC_CLIENT_H

#include "../rpc_src/message.grpc.pb.h"
#include "../rpc_src/message.pb.h"
#include <grpc++/grpc++.h>
#include <string>
#include "SingleClass.h"
#include <shared_mutex>
#include <unordered_map>
#include "../include/spin_lock.h"

class chat_service_rpc_client_item{

public:
    //一些客户端的发送
    bool notify_add_friend_apply(const std::string & from_email, const std::string  &to_email, const std::string & varify_text, const std::string &from_name);
    bool notify_friend_apply_res(const std::string&need_send_tar_email,const std::string &to_email,const bool & apply_res);
    bool notify_chat_text_msg(const std::string &from_email,const std::string &to_email,const int &msg_type,const std::string  &msg_id,const std::string &msg_data);
    chat_service_rpc_client_item(const std::string &ip_port);

private:
    std::shared_ptr<grpc::Channel> _channel;
    std::unique_ptr<message::chatServer::Stub> _stub;
};



class chat_service_rpc_client_pool:public SingleClass<chat_service_rpc_client_pool>{
public:
    std::shared_ptr<chat_service_rpc_client_item> add_item(const std::string &ip_port);
    std::shared_ptr<chat_service_rpc_client_item> find_and_get_item(const std::string &ip_port);
    ~chat_service_rpc_client_pool();

    std::shared_ptr<chat_service_rpc_client_item> get_rpc_client_item_through_email(const std::string &email);

private:
    friend class SingleClass<chat_service_rpc_client_pool>;
    chat_service_rpc_client_pool()=default;
    spin_lock spin_mtx;
    std::unordered_map<std::string,std::shared_ptr<chat_service_rpc_client_item>> client_pool;



};



#endif